//
//  MyFighterDetailThridCell.m
//  u76ho
//
//  Created by m-air-01 on 15/12/28.
//  Copyright © 2015年 LV. All rights reserved.
//

#import "MyFighterDetailThridCell.h"
@interface MyFighterDetailThridCell ()
{
    CGFloat totalW;
}
@end
@implementation MyFighterDetailThridCell

- (void)awakeFromNib {
    // Initialization code
}
-(void)setDataArr:(NSArray *)dataArr
{
    for (id btn in self.subviews) {
        if ([btn isKindOfClass:[UIButton class]]) {
            [btn removeFromSuperview];
        }
    }
    int j = 0;
    totalW = 0;
    _dataArr = dataArr;
    NSMutableArray * mArr = [[NSMutableArray alloc]init];
    for (int i = 0; i<dataArr.count; i++) {
        friendImpressionModel * model = dataArr[i];
        [mArr addObject:model.content];
    }
    //    CGFloat h = (self.frame.size.height - SIZETO6H(16)*2-SIZETO6H(10))/2;
    CGFloat h = 30;
    CGFloat myWidth = SCREEN_WIDTH - SIZETO6W(70);
    for (int i = 0; i<mArr.count; i++) {
        NSString * str = [mArr objectAtIndex:i];
        CGFloat tempW = [str widthOfSize:18] + SIZETO6W(10);
        totalW += tempW+SIZETO6W(10);
        if (totalW<=myWidth) {
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(SIZETO6W(15)+totalW-tempW-SIZETO6W(10),_friendImpressionLab.bottom+5+j*(30 + SIZETO6H(10)), tempW, h);
            [btn setTitle:mArr[i] forState:UIControlStateNormal];
            [btn setTitleColor:UIColorFromRGB(0x6ec844) forState:UIControlStateNormal];
            btn.layer.masksToBounds = YES;
            btn.layer.borderColor = [UIColorFromRGB(0x6ec844) CGColor];
            btn.layer.borderWidth = 1.0f;
            btn.layer.cornerRadius = 15;
            //            if (btn.titleLabel.text.length == 3) {
            //                btn.layer.cornerRadius = 12;
            //            }
            btn.titleLabel.font = [UIFont systemFontOfSize:15];
            [self addSubview:btn];
        }
        else
        {
            totalW = tempW+SIZETO6W(10);
            j = j+1;
            if (j == 2) {
                break;
            }
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(SIZETO6W(15), _friendImpressionLab.bottom+5+j*(h + SIZETO6H(10)), tempW, h);
            [btn setTitle:mArr[i] forState:UIControlStateNormal];
            [btn setTitleColor:UIColorFromRGB(0x6ec844) forState:UIControlStateNormal];
            btn.layer.masksToBounds = YES;
            btn.layer.borderColor = [UIColorFromRGB(0x6ec844) CGColor];
            btn.layer.borderWidth = 1.0f;
            btn.layer.cornerRadius = 15;
            //            if (btn.titleLabel.text.length == 3) {
            //                btn.layer.cornerRadius = 12;
            //            }
            btn.titleLabel.font = [UIFont systemFontOfSize:15];
            [self addSubview:btn];
            
        }
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
